﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PJAA_Inventory_and_AR___Prototype
{
    public partial class Issue_Invoice : Form
    {
        SQLMaster master;
        List<object[]> dataCompare = new List<object[]>();
        private Main_Menu MM;

        public Issue_Invoice(Main_Menu MM)
        {
            InitializeComponent();
            //added this block to make the form transparent
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.BackColor = Color.Transparent;

            this.MM = MM;
            master = new SQLMaster();
            dataCompare = master.loadClentList_withInv();
            LoadClientList();

        }

        private void LoadClientList()
        {
            IssueInv_DGV.Rows.Clear();
            foreach (object[] strArray in dataCompare)
            {
                if (IssueInv_Name_TxtBox.Text != string.Empty)
                {
                    if ((strArray[1] as string).ToLower().Contains(IssueInv_Name_TxtBox.Text.ToLower()))
                    //|| (strArray[2] as string).ToLower().Contains(SearchCl_Name_Txtbox.Text.ToLower()))
                    {
                        IssueInv_DGV.Rows.Add(strArray);
                    }
                }
                else
                    IssueInv_DGV.Rows.Add(strArray);

            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void Issue_Invoice_Load(object sender, EventArgs e)
        {

        }

        public string _ClName
        {
            get { return IssueInv_DGV.SelectedCells[1].Value.ToString(); }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 2)
            {
                if (IssueInv_DGV.SelectedCells[0].Value == null)
                { MessageBox.Show("Please select a customer first", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
                else
                {
                    MM._ClientName = _ClName;
                    Issue_Invoice_Button invoice = new Issue_Invoice_Button(IssueInv_DGV.SelectedCells[0].Value.ToString());//(IssueInv_DGV.SelectedCells[0].Value.ToString());
                    invoice.TopLevel = false;
                    invoice.Dock = DockStyle.Left;
                    panel1_issueInvoice.Controls.Clear();
                    panel1_issueInvoice.Controls.Add(invoice);
                    invoice.Show();
                    MM.Clientlbl.Visible = true;
                    MM.label_client.Visible = true;
                }
            }
        }

        private void IssueInv_Name_TxtBox_TextChanged(object sender, EventArgs e)
        {
            LoadClientList();
        }

        private void IssueInv_Name_Search_Btn_Click(object sender, EventArgs e)
        {

        }

        private void IssueInv_Close_Btn_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
